package com.honey.solr.schema.node;

import java.util.List;

import com.honey.compilation.xml.XmlElement;
import com.honey.solr.SchemaField;
import com.honey.solr.SolrConstant;
import com.honey.solr.SolrFactory;
import com.honey.solr.schema.SchemaNode;

public class CopyField implements SchemaNode {
	private SolrFactory solrFactory ;
	public CopyField(SolrFactory solrFactory){
		this.solrFactory = solrFactory;
	}
	
	@Override
	public void appendChildNode(XmlElement root){
		List<SchemaField> list = solrFactory.getSchemaFields();
		if ( list != null && list.size()>0 ){
			root.addComments("建立文本复制列");
			for(SchemaField schemaField : list){
				if( schemaField.getType().isString() )
					new XmlElement(root, "copyField")
					.addAttribute("source",schemaField.getName())
					.addAttribute("dest",SolrConstant.SOLR_SCHEMA_COPY_FIELD_NAME)
					;
			}
		}
	}
}
